package com.qezhhnjy.mall.coupon.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.coupon.Coupon;
import com.qezhhnjy.mall.common.entity.order.Order;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.coupon.feign.OrderFeign;
import com.qezhhnjy.mall.coupon.service.CouponService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 优惠券信息 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "优惠券信息接口")
@Slf4j
@RequestMapping("/coupon")
public class CouponController {
    @Resource
    private CouponService couponService;
    @Resource
    private OrderFeign orderFeign;

    @GetMapping("/get-order")
    @Operation(summary = "OpenFeign获取订单信息")
    public BaseResult<Order> getOrder(Long id) {
        return orderFeign.get(id);
    }

    @GetMapping("/get")
    @Operation(summary = "根据id获取优惠券信息信息")
    public BaseResult<Coupon> get(Long id) {
        Coupon coupon = couponService.getById(id);
        return BaseResult.success(coupon);
    }

    @PostMapping("/save")
    @Operation(summary = "新增优惠券信息信息")
    public BaseResult<Coupon> save(@RequestBody Coupon coupon) {
        couponService.save(coupon);
        return BaseResult.success(coupon);
    }

    @PutMapping("/update")
    @Operation(summary = "更新优惠券信息信息")
    public BaseResult<Coupon> update(@RequestBody Coupon coupon) {
        couponService.updateById(coupon);
        return BaseResult.success(coupon);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取优惠券信息信息")
    public BaseResult<Page<Coupon>> page(@RequestBody Page<Coupon> page) {
        couponService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除优惠券信息信息")
    public BaseResult<Long> delete(Long id) {
        couponService.removeById(id);
        return BaseResult.success(id);
    }
}

